#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>

int main()
{
    char c = 0;
    int P = 0;
    int PA = 0;
    long long count = 0;

    while (~(c = getchar()))
    {
        if ('P' == c)
        {
            P++;
        }
        else if ('A' == c)
        {
            PA += P;
        }
        else if ('T' == c)
        {
            count += PA;
        }
    }

    printf("%lld", count % 1000000007);
    return 0;
}

#include<stdio.h>

int main()
{
    int N = 0;
    scanf("%d", &N);
    int arr[200000];
    int max_num = 0;
    int max_sco = -1;
    int i = 0;

    for (i = 0; i < N; i++)
    {
        int num, sco;
        scanf("%d %d", &num, &sco);
        arr[num] += sco;
        if (arr[num] > max_sco)
        {
            max_sco = arr[num];
            max_num = num;
        }
    }

    printf("%d %d", max_num, max_sco);
    return 0;
}